<?php
declare(strict_types=1);

namespace app\command;

use app\common\service\order\ShopOrderService;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Log;
use think\facade\Queue;

/**
 * 商品超时撤回
 * 调试模式开启：php think goodsRevoke
 * 守护进程开启：php think goodsRevoke -m d
 */
class GoodsRevoke extends Command
{

    protected function configure()
    {
        // 指令配置
        $this->setName('goodsRevoke')
            ->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections", 'start')
            ->addOption('mode', 'm', Option::VALUE_OPTIONAL, '守护进程方式启动（-m d）')
            ->addOption('interval', 'i', Option::VALUE_OPTIONAL, '多长时间执行一次（秒）')
            ->setDescription('商品超时撤回');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        $output->writeln('goodsRevoke:execute');

        Log::write("商品超时撤回：".date('Y-m-d H:i:s'));
        try {
            $count = ShopOrderService::goodsRevokeOrder();
            if($count>0){
                Log::write("商品超时撤回数量：".$count);
            }
        } catch (\Exception $e) {
            Log::error("操作订单超时回池报错：".$e->getMessage());
        }
    }


    public function stop()
    {
    }


}
